package com.kun.video.ui.pane;

import com.kun.video.ui.KunComponent;
import com.kun.video.ui.progress.KunProgressBar;
import com.kun.video.util.ComUtil;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * TODO
 *
 * @author gzc
 * @since 2025/3/23
 **/
public class KunProgressBox extends VBox implements KunComponent {
    private static final Logger log = LoggerFactory.getLogger(KunProgressBox.class);
    private static final String CSS_CLASS = "kun-progress-box";

    private final KunProgressBar kunProgressBar = new KunProgressBar();
    private final Label taskLabel = new Label("等待任务...");

    public KunProgressBox() {
        super();
        initialize();
    }

    @Override
    public Parent getNode() {
        return this;
    }

    @Override
    public String getStyleName() {
        return CSS_CLASS;
    }

    @Override
    public void initStyleClass() {
        KunComponent.super.initStyleClass();
    }

    @Override
    public void initLayout() {
        getChildren().addAll(kunProgressBar, taskLabel);
    }

    @Override
    public void initStyle() {
        taskLabel.setStyle("-fx-font-size: 12px");
    }

    @Override
    public void initDimensions() {
    }

    @Override
    public void reactiveDimensions(double width, double height) {
        kunProgressBar.setPrefWidth(width);
        kunProgressBar.setMaxWidth(width);
    }

    @Override
    public void initListeners() {
    }

    @Override
    public void dispose() {
    }

    @Override
    public void initData() {
    }


    public KunProgressBar getProgressBar() {
        return this.kunProgressBar;
    }

    public Label getTaskLabel() {
        return this.taskLabel;
    }

    public void setTaskLabel(String taskDesc) {
        ComUtil.uiThreadRun(() -> this.taskLabel.setText(taskDesc));
    }

    public void setProgress(double value) {
        ComUtil.uiThreadRun(() -> this.kunProgressBar.setProgress(value));
    }

    public double getProgress() {
        return this.kunProgressBar.getProgress();
    }
}
